#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
ARG DOTNET_VERSION=6.0-alpine

FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION} AS base
WORKDIR /app
ENV TZ Asia/Shanghai
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache tzdata icu-libs && cp /usr/share/zoneinfo/${TZ} /etc/localtime \
    && echo ${TZ} > /etc/timezone
ARG CRM_VERSION=none
ENV CRM_VERSION=${CRM_VERSION} DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=0
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build

WORKDIR /src

COPY ["web/SourceCode/CRM.csproj", "SourceCode/"]
COPY ["web/VK/VK.csproj", "VK/"]
COPY ["web/RushMail/RushMail.csproj", "RushMail/"]
RUN dotnet restore "SourceCode/CRM.csproj" -s http://mirrors.local.com/nuget/v3/index.json --runtime alpine-x64
COPY web .
WORKDIR "/src/SourceCode"

FROM build AS publish
RUN dotnet publish "CRM.csproj" -c Release -o /app/publish  --no-restore \
    --runtime alpine-x64 \
    --self-contained false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY --from=crm_ui:latest /web/src/dist ./ui/
ENTRYPOINT ["dotnet", "CRM.dll"]